/**
 * Created by xin.zhang on 16/8/18.
 */
import React from 'react';

class Children extends React.Component {

    // 如果不需要在构造函数中使用可以不写，没有影响
    constructor(props, context) {
        super(props, context);
        console.log(context);
    }
    render() {
        return(

        <ul>
            <li>{'default context is: ' + this.context.value}</li>
            <li>{'parent context: ' + this._reactInternalInstance._context.value}</li>
            <li>{'owner context: ' + this._reactInternalInstance._currentElement._context.value}</li>
        </ul>)

        ;
    }
}
Children.contextTypes = {
    value: React.PropTypes.string
};

class Parent extends React.Component {
    getChildContext() {
        return { value: 'parent' };
    }

    render() {
        return (


            <div>
                {this.props.children}
            </div>


        );
    }
}
Parent.childContextTypes = {
    value: React.PropTypes.string
};

class App extends React.Component {
    getChildContext() {
        return { value: 'app' };
    }

    render() {
        return (
            <Parent>
                <Children />
            </Parent>
        );
    }
}
App.childContextTypes = {
    value: React.PropTypes.string
};
export default React.createClass({
    render() {
        return <div>
            <App/>
        </div>
    }
})